package com.lsz.flight_system.controller;

import com.lsz.flight_system.entity.BuyTicketsMessage;
import com.lsz.flight_system.service.BuyTicketsMessageService;
import com.lsz.flight_system.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/userTickets")
public class UserTicketsMessageController {

    @Autowired
    BuyTicketsMessageService buyTicketsMessageService;

    @ResponseBody
    @GetMapping("/buyTicketsMessages")
    public Result buyTicketsMessages(@RequestParam(value = "planeId",required = false) String planeId,
                                     @RequestParam(value = "username",required = false) String username){
        Map<String, Object> queryMap = new HashMap<>();

        queryMap.put("planeId",planeId);
        queryMap.put("username",username);

        List<BuyTicketsMessage> buyTicketsMessageList = buyTicketsMessageService.findAllBuyTicketsMessage(queryMap);

        return Result.ok(buyTicketsMessageList);
    }

    @PostMapping("/delBuyTicketsMessage/{id}")
    public Result delBuyTicketsMessage(@PathVariable Long id){
        if (buyTicketsMessageService.delBuyTicketsMessage(id)){
            return Result.ok();
        }
        return Result.fail("删除异常");
    }

    @GetMapping("/admin/updateTicketState")
    public Result updateUserBuyTicketStart(@RequestParam(value = "id") Long id,
                                           @RequestParam(value = "ticketState") String ticketState){
        if (buyTicketsMessageService.updateUserBuyTicketStart(id, ticketState)){
            return Result.ok();
        }
        return Result.fail("修改机票状态异常");
    }

}
